<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<button class="set">存储数据</button>
<button class="get">获取数据</button>
<button class="remove">删除数据</button>
<button class="del">清空所有数据</button>
<script>
    console.log(localStorage.getItem('username'));
    var ipt = document.querySelector('input');
    var set = document.querySelector('.set');
    var get = document.querySelector('.get');
    var remove = document.querySelector('.remove');
    var del = document.querySelector('.del');
    set.addEventListener('click', function () {
        //当我们点击了之后,可以把表单里面的值储存起来
        var val = ipt.value;
        sessionStorage.setItem('uname',val);
        sessionStorage.setItem('password',val);
    });
    get.addEventListener('click',function () {
        //当我们点击了之后,可以把表单里面的值获取起来
        console.log(sessionStorage.getItem('uname'));
    });
    remove.addEventListener('click',function () {
        //当我们点击了之后,可以把表单里面的值删除
        sessionStorage.removeItem('uname');
    });
    del.addEventListener('click',function () {
        //当我们点击了之后,可以把表单里面的值全部删除
        sessionStorage.clear();
    });
</script>
</body>
</html>
